package com.tanhua.server.controller;

import com.tanhua.server.service.SoundService;
import com.tanhua.server.vo.SoundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/peachblossom")
public class SoundController {

    @Autowired
    private SoundService soundService;


    /**
     * 接收
     * @return
     */
    @GetMapping
    public ResponseEntity<SoundVo> receiveSound(){
        try {
            SoundVo soundVo = soundService.receiveSound();
            if (null != soundVo) {
                return ResponseEntity.ok(soundVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    /**
     * 接收用户发送的语音文件并保存
     * 发送
     * @param soundFile
     */
    @PostMapping
    public ResponseEntity<Void> saveAudio(@RequestParam("soundFile") MultipartFile soundFile){
        try {
            String audioId = soundService.saveFile(soundFile);
            if (audioId != null) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
    /**
     * 探花-喜欢
     *
     * @param likeUserId
     * @return
    @GetMapping("{id}/like")
    public ResponseEntity<Void> likeUser(@PathVariable("id") Long likeUserId) {
        try {
            this.soundService.likeUser(likeUserId);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }*/
}
